HEADER monitoring
{
	// A simple voltage monitoring script...
	// By Mauro Grassi.
	// Switches a digital IO pin HIGH whenever the voltage is above
	// the maximum and switches the digital IO pin LOW when the voltage
	// is below the minimum, the maximum and minimum are constants
	// defined in the header...

	// We define the switching thresholds, allowing for hysteresis...
	#maximumVoltage=1.0;
	#minimumVoltage=0.7;

	// This example script also uses a local function...
}

SCRIPT monitoring
{
	// Define a Local Function!
	function @writeOnOff(1)
	{
		if($1)
		{
			print "ON";
		}
		else
		{
			print "OFF";
		}
	}
	
	// Basic Script Showing How To Read and Log an Analog Sensor, 
	// by Mauro Grassi.
	// Execution Begins here, after the local function definitions...

	clearFile "monitoring output.txt";
	@@openADC(#A0);
	PRECISION(2);
	WHILE(1)
	{
		$V=@@readV(#A0);
		if(($V<#maximumVoltage) AND ($V>#minimumVoltage))
		{
			// within range, so don't do anything...
		} 
		else
		if($V<#minimumVoltage)
		{
			@@setIO(#D0, #lowIO);
		}
		else
		{
			@@setIO(#D0, #highIO);
		}
		print pf(#timeIfSet), " The Voltage is: ", $V, " The output is: ";
		// we use a local function call here...
		@writeOnOff(@@getIO(#D0));
		print newline;
		sleep(5);
	}
}
